home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Networking / TransferProvider1.0d1 / TransferProvider.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-02  |  3.2 KB  |  123 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        TransferProvider.c
  3.  
  4.     Contains:    Sample that shows how to use OTTransferProviderOwnership.
  5.  
  6.     Written by:    Quinn "The Eskimo!"
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     You may incorporate this sample code into your applications without
  13.     restriction, though the sample code has been provided "AS IS" and the
  14.     responsibility for its operation is 100% yours.  However, what you are
  15.     not permitted to do is to redistribute the source as "DSC Sample Code"
  16.     after having made changes. If you're going to re-distribute the source,
  17.     we require that you make it clear in the source that the code was
  18.     descended from Apple Sample Code, but that you've made changes.
  19. */
  20.  
  21. ////////////////////////////////////////////////////////////
  22. // Pick up general Open Transport stuff.
  23.  
  24. #include <OpenTransport.h>
  25.  
  26. ////////////////////////////////////////////////////////////
  27. // Pick up OT debugging macros.
  28.  
  29. #include <OTDebug.h>
  30.  
  31. ////////////////////////////////////////////////////////////
  32. // Pick up standard C libraries.
  33.  
  34. #include <stdio.h>
  35.  
  36. ////////////////////////////////////////////////////////////
  37. // Get prototypes for the factory.
  38.  
  39. #include "ProviderFactory.h"
  40.  
  41. ////////////////////////////////////////////////////////////
  42. // OTDebugStr is not defined in any of the interfaces,
  43. // but it is in the libraries.
  44.  
  45. extern void OTDebugStr(char *str);
  46.  
  47. ////////////////////////////////////////////////////////////
  48.  
  49. static OSStatus GetProviderFromFactory(void)
  50.     // This routine calls FactoryCreateEndpoint to
  51.     // create an endpoint that is owned by the provider
  52.     // factory, and then uses OTTransferProviderOwnership
  53.     // to let Open Transport know that the newly created
  54.     // endpoint is owned by us.  It then does a simple
  55.     // operation an the endpoint, just to make sure
  56.     // everything works OK.
  57. {
  58.     OSStatus err;
  59.     EndpointRef originalEndpoint;
  60.     OTClient originalOwner;
  61.     EndpointRef newEndpoint;
  62.     TEndpointInfo newEndpointInfo;
  63.  
  64.     // Use the factory library to create an endpoint.
  65.     
  66.     err = FactoryCreateEndpoint(&originalEndpoint, &originalOwner);
  67.     
  68.     if (err == noErr) {
  69.     
  70.         // Transfer the ownership of that endpoint, so that OT knows
  71.         // we now own it.
  72.         
  73.         newEndpoint = OTTransferProviderOwnership(originalEndpoint, originalOwner, &err);
  74.  
  75.         if (err == noErr) {
  76.             
  77.             // We can now use newEndpoint as if we created it.  We call
  78.             // OTGetEndpointInfo as an example of an operation on the
  79.             // endpoint.
  80.  
  81.             err = OTGetEndpointInfo(newEndpoint, &newEndpointInfo);
  82.             
  83.             if (err == noErr) {
  84.                 printf("Maximum size of endpoint address = %ld.\n", newEndpointInfo.addr);
  85.             }
  86.             
  87.             OTCloseProvider(newEndpoint);
  88.         }
  89.     }
  90.     
  91.     return err;
  92. }
  93.  
  94. ////////////////////////////////////////////////////////////
  95.  
  96. void main(void)
  97.     // The main line.  This inits our connection to OpenTransport,
  98.     // and then inits the provider factory library.  It then
  99.     // calls GetProviderFromFactory to demo the use of
  100.     // OTTransferProviderOwnership.
  101. {
  102.     OSStatus err;
  103.     
  104.     err = InitOpenTransport();
  105.     if (err == noErr) {
  106.     
  107.         err = InitProviderFactory();
  108.         
  109.         if (err == noErr) {
  110.             
  111.             err = GetProviderFromFactory();
  112.  
  113.             CloseProviderFactory();
  114.         }
  115.     
  116.         CloseOpenTransport();
  117.     }
  118.     if (err == noErr) {
  119.         printf("Success!\n");
  120.     } else {
  121.         printf("Failed with error %ld.\n", err);
  122.     }
  123. }